<html>
<head><title>Add User</title></head>
<body>
<?php
	include "config.php";

	$name = $_POST["name"];
	$uname = $_POST["username"];
	$pw1 = $_POST["pw1"];
	$pw2 = $_POST["pw2"];
	$influence = $_POST["influence"];
	
	if(!($pw1 == $pw2))
	{
		echo "Error: Passwords do not match.";
	}
	else{
		$usr_query = "SELECT * FROM users WHERE username = '" . $uname . "'";
		$usr_result = mysql_query($usr_query);
		if(mysql_num_rows($usr_result) > 0)
		{
			echo "Error: User with that name already exists.";
		}
		else{
			$insert_query = "INSERT INTO users (username, password, name, influence) VALUES ('".$uname."', '".$pw1."', '".$name."', ".$influence.")";
			$result = mysql_query($insert_query);
			if($result)
			{
				echo "User " . $uname . " added to database.";
			}else{
				echo "FAILED to add user to database.";
			}
		}
		
	}
	?>
	<br /><a href="addUser.html">Back to Add User</a><br />
	<a href="welcome.php">Return to Welcome Page</a>
	</body>
	</html>